package com.itheima.factory;

import com.itheima.controller.IManagerController;
import com.itheima.controller.IStudentController;
import com.itheima.controller.ImplManagerController;
import com.itheima.dao.IManagerDao;
import com.itheima.dao.IStudentDao;
import com.itheima.service.IManagerService;
import com.itheima.service.IStudentService;

import java.io.IOException;
import java.util.Properties;

public class Factory {
    private static final Properties prop = new Properties();

    static {
        try {
            prop.load(ClassLoader.getSystemResourceAsStream("bean.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static IStudentController getStudentController() {
        String classname= prop.getProperty("IStudentController");
        IStudentController controller = null;
        try {
            Class<?> clazz = Class.forName(classname);
            controller = (IStudentController)clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return controller;
    }

    public static IStudentService getStudentService() {
        String classname = prop.getProperty("IStudentService");
        Object o = null;
        try {
            Class<?> clazz = Class.forName(classname);
            o = clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IStudentService)o;
    }
    public static IStudentDao getStudentDao(){
        String classname = prop.getProperty("IStudentDao");
        Object o = null;
        try {
            Class<?> clazz = Class.forName(classname);
            o = clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IStudentDao)o;
    }


    public static IManagerDao getManagerDao() {
        String classname  = prop.getProperty("IManagerDao ");
        Object o = null;
        try {
            Class<?> clazz = Class.forName(classname);
            o = clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IManagerDao)o;
    }

    public static IManagerService getManagerService() {
        String classname = prop.getProperty("IManagerService");
        Object o = null;
        try {
            Class<?> clazz = Class.forName(classname);
            o = clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IManagerService)o;

    }

    public static IManagerController getManagerController() {
        String classname = prop.getProperty("IManagerController");
        Object o = null;
        try {
            Class<?> clazz = Class.forName(classname);
            o = clazz.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (ImplManagerController)o;
    }


}
/*import com.itheima.controller.IMangaerController;
import com.itheima.controller.IStudentController;
import com.itheima.controller.ImplManagerController;
import com.itheima.controller.ImplStudentController;
import com.itheima.dao.IManagerDao;
import com.itheima.dao.IStudentDao;
import com.itheima.dao.ImplManagerDao;
import com.itheima.dao.ImplStudentDao;
import com.itheima.service.IManagerService;
import com.itheima.service.IStudentService;
import com.itheima.service.ImplManagerService;
import com.itheima.service.ImplStudentService;

public class Factory {
    public static IStudentDao getStudentDao() {
        return new ImplStudentDao();
    }

    public static IStudentService getStudentService() {
        return new ImplStudentService();
    }

    public static IStudentController getStudentController() {
        return new ImplStudentController();
    }

    public static IManagerDao getManagerDao() {
        return new ImplManagerDao();
    }

    public static IManagerService getManagerService() {
        return new ImplManagerService();
    }

    public static IMangaerController getManagerController() { return new ImplManagerController();
    }*/




